package com.lewis.file;

import java.io.*;

/**
 * @author Lewis - 398529803@qq.com
 * @date 2022/3/24 - 18:12
 */
public class test {

	public static void main(String[] args) throws Exception {
		String filePath = "E:\\lewis-springboot-vue\\list.txt";
		FileInputStream fin = new FileInputStream(filePath);
		InputStreamReader reader = new InputStreamReader(fin);
		BufferedReader buffReader = new BufferedReader(reader);
		String strTmp = "";
		while ((strTmp = buffReader.readLine()) != null) {
			String[] split = strTmp.split("\\.");
			if (split[split.length - 1].equals("java")) {

				// System.out.println(strTmp);

				String[] split1 = strTmp.split("\\\\");
				String fileName = split1[split1.length - 1].replace(".java", ".txt");
				// System.out.println("the last fileName ==> " + fileName);

				StringBuilder filePathWait = new StringBuilder();
				for (int i = 0; i < split1.length - 1; i++) {
					filePathWait.append(split1[i]).append("\\");
				}
				// System.out.println("the last file path ==> " + filePathWait);

				File file= new File(filePathWait + fileName);
				// circleMethod(file);
				if (file.createNewFile()) {
					System.out.println("success ==> " + filePathWait + fileName);
				} else {
					System.out.println("fail ==> " + filePathWait + fileName);
				}

			}
		}
		buffReader.close();
	}

	private static FileOutputStream out;

	private static void circleMethod(File file) {
		// TODO Auto-generated method stub
		if (file.isDirectory()) {
			createFile(file);
			File[] fileList = file.listFiles();
			for (int i = 0; i < fileList.length; i++) {
				circleMethod(fileList[i]);
			}
		}
	}

	private static void createFile(File file) {
		// TODO Auto-generated method stub
		String nameDir = file.getAbsoluteFile()+ File.separator+"111.txt";

		try {
			out = new FileOutputStream(nameDir);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String str= "xxxx";
		byte[] b =str.getBytes();
		for (int i = 0; i < b.length; i++) {
			try {
				out.write(b[i]);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		try {
			out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
